import java.util.*;

public class Solution {
    public boolean isValid(String s){
        int len = s.length();
        if(len % 2 == 1){
            return false;
        }//如果字符串长度为奇数，直接返回false

        Map<Character,Character> match = new HashMap<Character, Character>(){{
            put('}','{');
            put(']','[');
            put(')','(');
        }};//先用哈希表对左、右括号进行匹配

        //先去遍历左侧的数组，先出后匹配，可以使用栈来解决
        Deque<Character> stack = new LinkedList<Character>();
        for (int i = 0; i < len; i++) {
            char ch = s.charAt(i);
            if(match.containsKey(ch)){
               if(stack.isEmpty()||stack.peek() != match.get(ch)) {//如果字符串为空，或者左括号无法匹配，返回false
                   return false;
               }
               stack.pop();
            }else{
                stack.push(ch);
            }
        }
        return stack.isEmpty();//如果栈为空，说明所有的开括号都找到了对应的闭括号，并且它们都是正确匹配的
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String s = in.nextLine();
            Solution solution = new Solution();
            boolean result = solution.isValid(s);
            System.out.println(result);
        }
    }
}
